package org.spacetrader.seam2project.controller;

import java.util.List;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.spacetrader.seam2project.model.PersonService;
import org.spacetrader.seam2project.model.entity.Person;

@Name("helloWorld")
@Scope(ScopeType.EVENT)
public class HelloWorld {
	@In(create=true)
	private PersonService personService;
	
	private String greeting;
	
	private Person editingPerson;
	
	private List<Person> personList;
	
	@Create
	public void init() { 
		greeting = "Hello World!";
		
		editingPerson = new Person();
		
		personList = personService.getPersonList();
	}
		
	public String savePerson() {
		personService.savePerson(editingPerson);
		
		editingPerson = new Person();
		
		personList = personService.getPersonList();
		
		return "/index.xhtml";
	}
	
	@BypassInterceptors
	public String getGreeting() {
		return greeting;
	}
	
	@BypassInterceptors
	public Person getEditingPerson() {
		return editingPerson;
	}

	@BypassInterceptors
	public List<Person> getPersonList() {
		return personList;
	}
}
